#include "AuthenticationMain.h"
#include "ui_AuthenticationMain.h"
#include "AuthenticationList.h"
#include "AuthenticationCreate.h"

#include <QToolBar>
#include <QMenuBar>

AuthenticationMain::AuthenticationMain(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::AuthenticationMain)
{
    ui->setupUi(this);
    this->InitUi();
}

void AuthenticationMain::InitUi()
{
    QToolBar* toolBar = this->addToolBar("操作");
    toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    toolBar->setIconSize(QSize(24, 24));

    QList<QString> iconPath_list = {
        "E:/ComplexProject/IOT_DM/IOT_DM_Client/IOT_DM/Resources/list.svg",
        "E:/ComplexProject/IOT_DM/IOT_DM_Client/IOT_DM/Resources/create.svg",
        //"E:/ComplexProject/IOT_DM/IOT_DM_Client/IOT_DM/Resources/edit.svg",
        //"E:/ComplexProject/IOT_DM/IOT_DM_Client/IOT_DM/Resources/delete.svg",
    };

    QList<QAction*> action_list = {
        new QAction(QIcon(iconPath_list[0]),"认证列表"),
        new QAction(QIcon(iconPath_list[1]),"添加认证"),
        //new QAction(QIcon(iconPath_list[2]),"编辑认证"),
        //new QAction(QIcon(iconPath_list[3]),"删除认证"),
    };



    QList<QWidget*> page_list = {
        new AuthenticationList(),
        //new AuthenticationList(),
        new AuthenticationCreate(),
        //new AuthenticationList(),
    };

    int index = 0;
    foreach(QAction* action, action_list)
    {
        this->ui->stackedWidget->insertWidget(index, page_list[index]);

        toolBar->addAction(action);


        connect(action, &QAction::triggered, this, [=](){
            this->ui->stackedWidget->setCurrentIndex(index);
        });
        index++;
    }

    this->ui->stackedWidget->setCurrentIndex(0);

}

AuthenticationMain::~AuthenticationMain()
{
    delete ui;
}
